package com.mdlaser.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mdlaser.annotation.CommonRest;
import com.mdlaser.entity.WishLanguage;
import com.mdlaser.service.IWishLanguageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mdlaser
 * @since 2024-05-16
 */
@RestController
@CommonRest
@RequestMapping("/wish-language")
@Tag(name = "祝福语管理")
public class WishLanguageController {

    @Autowired
    IWishLanguageService wishLanguageService;

    @Operation(summary = "删除祝福语")
    @GetMapping("/del")
    public void del(@RequestParam String languageId) {
        wishLanguageService.getBaseMapper().deleteById(languageId);
    }


    @Operation(summary = "根据Id获取祝福语")
    @GetMapping("/getById")
    public WishLanguage getById(@RequestParam String languageId) {
        return wishLanguageService.getBaseMapper().selectById(languageId);
    }


    @Operation(summary = "根据Id修改祝福语")
    @PostMapping("/editById")
    public void editById(@RequestBody WishLanguage wishType) {
        wishLanguageService.getBaseMapper().updateById(wishType);
    }


    @Operation(summary = "获取所有祝福语")
    @GetMapping("/list")
    public List<WishLanguage> list() {
        return wishLanguageService.getBaseMapper().selectList(null);
    }

    @Operation(summary = "根据祝福类型获取祝福语")
    @GetMapping("/getLanguageByType")
    public List<WishLanguage> getLanguageByType(@RequestParam String wishId) {
        LambdaQueryWrapper<WishLanguage> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WishLanguage::getWishId, wishId);
        return wishLanguageService.getBaseMapper().selectList(queryWrapper);
    }

    @Operation(summary = "新增祝福语")
    @PostMapping("/add")
    public void add(@RequestBody WishLanguage wishType) {
        wishLanguageService.getBaseMapper().insert(wishType);
    }

}
